<?php
/**

 //  The DoYouHaoBaby PHP FrameWork - db
 //  +---------------------------------------------------------------------
 //
 //  “Copyright”
 //  +---------------------------------------------------------------------
 //	 | (C) 2010 - 2011 http://doyouhaobaby.net All rights reserved.
 //	 | This is not a free software, use is subject to license terms
 //  +---------------------------------------------------------------------
 //
 //  “About This File”
 //  +---------------------------------------------------------------------
 //	 | db Index控制器
 //  +---------------------------------------------------------------------

*/

!defined('DYHB_PATH') && exit;

class IndexController extends Controller{


	/**
	 * 首页 < 默认访问 >
	 *
	 * @access public
	 * @return void
	 */
    public function index(){
       
	    $oModel  = FormModel::F(); 
    	
        // 普通的列表查询
        $arrList  = $oModel->limit( 5 )
			        ->order('`form_id` DESC')
			        ->asArray()
			        ->all()
			        ->query( );

		// 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $this->assign( 'arrList',$arrList );
        
        /** ======================== 更多 ========================= */

        $arrData = array( ); 
		
        // 示例1，占位符       
        $oModel->all()
			   ->where( 'form_id=?',1 )
			   ->query(); 

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );
	
        $arrData = array( ); 
		
        // 示例2，最普通的
        $arrData['form_id'] = array( 'LIKE','dyhb%' );
        $arrData['form_title'] = array( 'neq','李洪志' );
        $arrData['create_date'] = 123456789;         
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query();  
          
        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $arrData = array();

        // 示例3，自动模糊
        $arrData['form_id'] = array( 'LIKE','dyhb%' );
        $arrData['form_title'] ='李洪志';
        $arrData['create_date']= 123456789;         
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query(); 

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );
		 
        $arrData=array();

        // 示例4，between
        $arrData['form_id'] = array('between','1,2');        
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query(); 

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $arrData = array();

        // 示例5，等效
        $arrData['form_id'] = array('between',array('1','2'));        
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query(); 
            
        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $arrData =array( );

        // 示例6，[not]in
        $arrData['form_id'] = array('in','1,2,3');        
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query(); 
        
        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $arrData = array();

        //示例7，等效
        $arrData['form_id'] = array('not in',array('1','2','3'));        
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query();

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );
        
        $arrData = array();

        // 示例8，实例exp
        $arrData['form_id']=array('exp','IN (1,2,3)');
        $oModel->reset( DbSelect::WHERE )
			   ->all()
			   ->where( $arrData )
			   ->query();   
        
        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        /** ======================== end ========================= */

        // 示例9，带条件查询
        $arrCondition['form_id'] = array('gt',0); 
        $arrCondition['form_status'] = 1; 
        $arrVo = $oModel
			     ->reset( DbSelect::WHERE )
			     ->setColumns('form_id,form_title')
			     ->where( $arrCondition )
			     ->all()
			     ->asArray()
			     ->query(); 

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $this->assign( 'arrVo',$arrVo ); 
        
        $arrData =array();

        // 示例10，组合查询
        $arrMap['form_id']=array('NOT IN','1,6,9'); 
        $arrMap['form_title']    = array(array('like','dyhb%'),array('like','小牛哥%'),'or'); 
        $arrList = $oModel
			       ->reset( DbSelect::WHERE )
			       ->reset( DbSelect::ORDER )
			       ->order('`form_id` DESC')
			       ->limit( 0,5 )
			       ->asArray()
			       ->all()
			       ->where( $arrMap )
		           ->query(); 
	
	    // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $this->assign('arrList2',$arrList ); 
             
        $arrData = array();

        // 示例11，动态查询
        $arrVo  = $oModel
			      ->reset( DbSelect::WHERE )
			      ->getByform_email('log1990@126.com'); 

        // 开始捕获错误
		if( $oModel->isError() )
		     $this->E(  $oModel->getErrorMessage() );

        $this->assign('arrVo2',$arrVo );

        $this->display( );

    }

}
